function save_data(){

    if($("#upload_title").val()=="" ){
        layer.alert("填个标题吧！");
        return fasle;
    }
    //页面展示跳转地址
    if(this_module.charAt(this_module.indexOf("_")+1)=="1"){
        var belong="";
        if($("#select_type").val()!="turn"){
            $("#upload_url").val("/index.php?show=" + $("#data_id").attr("module"));
        }
    }
    else{
        var belong=$("#select_belong").val();
    }
    if(this_module.charAt(this_module.indexOf("_")+1)=="2"){
        $("#upload_url").val("#");
    }
    //排序不填默认为0
    if($("#upload_order").val()==""){
        $("#upload_order").val(0);
    }
    //跳转链接不填默认为#
    if($("#upload_url").val()==""){
        $("#upload_url").val("#");
    }
    var index1=layer.load(
        3,
        {shade:[0.5,'#000']}
    )

    $.post(
        "controler.php",
        {
            handle:"sava_frame_data",
            id:$("#data_id").html(),
            title:$("#upload_title").val(),
            data_order:$("#upload_order").val(),
            type:$("#select_type").val(),
            status:$("#select_status").val(),
            url:$("#upload_url").val(),
            content:"",
            belong:belong,
            module:$("#data_id").attr("module"),
            frame:this_module,
        },
        function(msg){
            layer.close(index1);
            result(msg);
        }
    )
}

function dele(id){
    layer.confirm('确定要删除此记录吗？', {icon: 3, title:'提示'}, function(index){
        layer.close(index);
        var index1=layer.load(
            3,
            {shade:[0.5,'#000']}
        )
        $.post(
                "controler.php",
                {
                    handle:"dele_frame_data",
                    id:id
                },
                function (msg) 
                {
                    layer.close(index1);
                    result(msg);
            });
        });
}

function result(msg){
    try {
        var data=JSON.parse(msg);
        if(data.code=="done"){
            $(".zhemu").css("display","none");
            check();
        }
        else{
            layer.alert(data.msg);
        }
    } catch(e) {
        layer.alert("请求出错，请稍后再试！");
    }
}
//获取模块信息
function check(){
    var index1=layer.load(
        3,
        {shade:[0.5,'#000']}
    )

    $.post(
            "controler.php",
            {
                handle:"frame_data",
                lavel:this_module.charAt(this_module.indexOf("_")+1)
            },
            function (msg) 
            {   layer.close(index1);
                var data=JSON.parse(msg);
                var show_string="";
                var type=[];
                type['module']="空白页面";
                type['turn']="跳转链接";
                type['lunbo']="轮播展示";
                type['pic_show_1']="宫格图片1";
                type['pic_show_2']="宫格图片2";
                type['pic_show_3']="宫格图片3";
                type['regist']="申请注册表";
                var status=[];
                status['1']="显示";
                status['0']="隐藏";
                //一级框架
                if(this_module=="frame_1"){
                    for (let index = 0; index < data.length; index++) {
                        show_string=show_string + '<div class="frame_item"><div class="frame_item_left  frame_item_name">' + data[index]['module_name'] + '</div><div class="frame_item_left  frame_item_type" type="' + data[index]['type'] + '">' + type[data[index]['type']] + '</div><div class="frame_item_left  frame_item_url">' + data[index]['url'] + '</div><div class="frame_item_right frame_item_status" status="' + data[index]['status'] + '">' + status[data[index]['status']] + '</div><div class="frame_item_right frame_item_dele"><button onclick="dele(' + "'" + data[index]['id'] + "'" + ')">删除</button></div><div class="frame_item_right frame_item_edit"><button onclick="modify_frame(' + "'" + data[index]['id'] + ',' + data[index]['module'] + ',' + data[index]['module_name'] + ',' + data[index]['type'] + ',' + data[index]['status'] + ',' + data[index]['data_order'] + ',' + data[index]['url'] + "'" + ')">修改</button></div><div class="data_order">' + data[index]['data_order'] + '</div></div>';
                    }
                    show_string= '<div class="head_div"><button onclick="javascript:add_module()" >添加新模块</button></div><div class="frame_item frame_th"><div class="frame_item_left  frame_item_name">模块名</div><div class="frame_item_left  frame_item_type">模块类型</div><div class="frame_item_left  frame_item_url">跳转地址</div><div class="frame_item_right frame_item_status">状态</div><div class="frame_item_right frame_item_dele">删除</div><div class="frame_item_right frame_item_edit">修改</div><div class="data_order" style="line-height: 30px;padding:0;">排序</div></div>'+ show_string;
                }
                //二级框架
                if( this_module=="frame_2"){
                    for (let index = 0; index < data.length; index++) {
                        show_string=show_string + '<div class="frame_item"><div class="frame_item_left  frame_item_name">' + data[index]['module_name'] + '</div><div class="frame_item_left  frame_item_type" type="' + data[index]['type'] + '">' + type[data[index]['type']] + '</div><div class="frame_item_left  frame_item_type" type="' + data[index]['belong'] + '">' + data[index]['belong_name'] + '</div><div class="frame_item_left  frame_item_url">' + data[index]['url'] + '</div><div class="frame_item_right frame_item_status" status="' + data[index]['status'] + '">' + status[data[index]['status']] + '</div><div class="frame_item_right frame_item_dele"><button onclick="dele(' + "'" + data[index]['id'] + "'" + ')">删除</button></div><div class="frame_item_right frame_item_edit"><button onclick="modify_frame1(' + "'" + data[index]['id'] + ',' + data[index]['module'] + ',' + data[index]['module_name'] + ',' + data[index]['type'] + ',' + data[index]['status'] + ',' + data[index]['data_order'] + ',' + data[index]['url'] + "'" + ')">修改</button></div><div class="data_order">' + data[index]['data_order'] + '</div></div>';
                    }
                    show_string= '<div class="head_div"><button onclick="javascript:add_module1()" >添加新模块</button></div><div class="frame_item frame_th"><div class="frame_item_left  frame_item_name">模块名</div><div class="frame_item_left  frame_item_type">模块类型</div><div class="frame_item_left  frame_item_belong">所属模块</div><div class="frame_item_left  frame_item_url">跳转地址</div><div class="frame_item_right frame_item_status">状态</div><div class="frame_item_right frame_item_dele">删除</div><div class="frame_item_right frame_item_edit">修改</div><div class="data_order" style="line-height: 30px;padding:0;">排序</div></div>'+ show_string;
                }  
                $("." +this_module).html(show_string);

    });
}
